package dhm.com.hpx.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import dhm.com.hpx.R;
import dhm.com.hpx.activity.ArticleActivity;
import dhm.com.hpx.activity.ExtensionarticleActivity;
import dhm.com.hpx.activity.ExtensionradioActivity;
import dhm.com.hpx.activity.VideoActivity;
import dhm.com.hpx.adapter.ExtensionAdapter;
import dhm.com.hpx.adapter.MessageArticleadapter;
import dhm.com.hpx.adapter.MessageCollectVideoadapter;
import dhm.com.hpx.adapter.MessageColletArticleadapter;
import dhm.com.hpx.adapter.MessageVideoadapter;
import dhm.com.hpx.base.BaseFragment;
import dhm.com.hpx.base.Presenter.PressenterImpl;
import dhm.com.hpx.base.netWork.Constant;
import dhm.com.hpx.base.netWork.LoginContract;
import dhm.com.hpx.entity.Bean;
import dhm.com.hpx.entity.FabulousArticleBean;
import dhm.com.hpx.entity.FabulousVideoBean;
import dhm.com.hpx.entity.FavoriteArticleBean;
import dhm.com.hpx.entity.FavoriteVideoBean;
import dhm.com.hpx.entity.GetExtensionListBean;
import dhm.com.hpx.utils.SpUtils;

public class MessageFragment extends BaseFragment implements LoginContract.IView {
    Unbinder unbinder;
    @BindView(R.id.change)
    TextView change;
    @BindView(R.id.text_like)
    TextView textLike;
    @BindView(R.id.line_like)
    TextView line_like;
    @BindView(R.id.text_likedVideo)
    TextView text_likedVideo;
    @BindView(R.id.line_likedVideo)
    TextView line_likedVideo;
    @BindView(R.id.line_liked)
    TextView line_liked;
    @BindView(R.id.image_like)
    ImageView imageLike;
    @BindView(R.id.text_liked)
    TextView textLiked;
    @BindView(R.id.image_liked)
    ImageView imageLiked;
    @BindView(R.id.recy)
    XRecyclerView recy;
    @BindView(R.id.title)
    TextView title;

    private PressenterImpl pressenter;
    private String uid;
    private List<FabulousArticleBean.DataBean> fabulousArticle;
    private MessageArticleadapter messageArticleadapter;
    private List<FabulousVideoBean.DataBean> fabulousVideo;
    private MessageVideoadapter messageVideoadapter;
    private List<FavoriteArticleBean.DataBean> favoriteArticle;
    private MessageColletArticleadapter messageColletArticleadapter;
    private List<FavoriteVideoBean.DataBean> favoriteVideo;
    private MessageCollectVideoadapter messageCollectVideoadapter;

    @Override
    protected int getLayout() {
        return R.layout.fragment_message;
    }

    int page=1;

    @Override
    protected void initView() {
        pressenter=new PressenterImpl();
        pressenter.attachView(this);

        uid = SpUtils.getString(getActivity(), "uid");

        LinearLayoutManager manager=new LinearLayoutManager(getActivity());
        manager.setOrientation(LinearLayoutManager.VERTICAL);

        recy.setLayoutManager(manager);

        recy.setLoadingMoreEnabled(true);
        recy.setPullRefreshEnabled(true);
        showPopwindow();
        showPopwindows();
        initData();
    }

    private void getLikeArticle() {

        recy.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                page=1;
                getLikeArticle();
            }

            @Override
            public void onLoadMore() {
                getLikeArticle();
            }
        });


        Map<String,String> map=new HashMap();
        map.put("token", Constant.TOKEN);
        map.put("uid",uid);
        map.put("page",page+"");

        pressenter.sendMessage(getActivity(),Constant.listArticlesQuery_fablulous,map, FabulousArticleBean.class);

    }

    private void getLikeVideo() {
        recy.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                page=1;
                getLikeVideo();
            }

            @Override
            public void onLoadMore() {
                getLikeVideo();
            }
        });


        Map<String,String> map=new HashMap();
        map.put("token", Constant.TOKEN);
        map.put("uid",uid);
        map.put("page",page+"");

        pressenter.sendMessage(getActivity(),Constant.listVideoQuery_fablulous,map, FabulousVideoBean.class);
    }

    private void getColletArticle() {
        recy.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                page=1;
                getColletArticle();
            }

            @Override
            public void onLoadMore() {
                getColletArticle();
            }
        });

        Map<String,String> map=new HashMap();
        map.put("token", Constant.TOKEN);
        map.put("uid",uid);
        map.put("page",page+"");
        pressenter.sendMessage(getActivity(),Constant.listArticlesQuery,map, FavoriteArticleBean.class);
    }

    private void getColletVideo() {
        recy.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                page=1;
                getColletVideo();
            }

            @Override
            public void onLoadMore() {
                getColletVideo();
            }
        });

        Map<String,String> map=new HashMap();
        map.put("token", Constant.TOKEN);
        map.put("uid",uid);
        map.put("page",page+"");
        pressenter.sendMessage(getActivity(),Constant.listVideoQuery,map, FavoriteVideoBean.class);
    }

    String type="1";

    private void clearlike() {
        Map<String,String> map=new HashMap();
        map.put("token", Constant.TOKEN);
        map.put("uid",uid);
        map.put("type",type);
        pressenter.sendMessage(getActivity(),Constant.fabulousclear_del,map, Bean.class);
    }
    private void clearcollection() {
        Map<String,String> map=new HashMap();
        map.put("token", Constant.TOKEN);
        map.put("uid",uid);
        map.put("type",type);
        pressenter.sendMessage(getActivity(),Constant.clear_del,map, Bean.class);
    }


    private View rootView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.fragment_message, container, false);
        }
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    protected void initData() {
        getColletArticle();
    }

    @Override
    public void requesta(Object data) {
        if (data instanceof FabulousArticleBean){
            FabulousArticleBean listBean= (FabulousArticleBean) data;
            if (listBean.getCode()==1){
                if (page==1){
                    recy.setVisibility(View.VISIBLE);
                    fabulousArticle = listBean.getData();
                    messageArticleadapter = new MessageArticleadapter(getActivity());
                    messageArticleadapter.setdeleteClick(new MessageArticleadapter.OnClick() {
                        @Override
                        public void item(int posttion) {
                            if (fabulousArticle.get(posttion).getFabulousType()==1){
                                Intent intent=new Intent(getActivity(), ArticleActivity.class);
                                intent.putExtra("article_id",fabulousArticle.get(posttion).getArticleId()+"");
                                intent.putExtra("coverImg",fabulousArticle.get(posttion).getCoverImg()+"");
                                startActivity(intent);
                            }else {
                                Intent intent=new Intent(getActivity(), ExtensionarticleActivity.class);
                                intent.putExtra("extension_id",fabulousArticle.get(posttion).getArticleId()+"");
                                startActivity(intent);
                            }
                        }
                    });
                    messageArticleadapter.setaddClick(new MessageArticleadapter.OnIntentClick() {
                        @Override
                        public void item(int position) {
                            Map<String,String> map=new HashMap<>();
                            map.put("token",Constant.TOKEN);
                            map.put("uid",uid);
                            map.put("type","1");
                            map.put("cid",fabulousArticle.get(position).getFabulousId()+"");

                            pressenter.sendMessage(getActivity(),Constant.fabulouscancel,map,Bean.class);
                            fabulousArticle.remove(position);
                            messageArticleadapter.setList(fabulousArticle);
                        }
                    });


                    recy.setAdapter(messageArticleadapter);
                }else {
                    fabulousArticle.addAll(listBean.getData());
                }
                messageArticleadapter.setList(fabulousArticle);
                page++;
            }else {
                if (page==1){
                    recy.setVisibility(View.GONE);
                }
                Toast.makeText(getActivity(), listBean.getMessage(), Toast.LENGTH_SHORT).show();
            }
            recy.refreshComplete();
            recy.loadMoreComplete();
        }else if (data instanceof FabulousVideoBean){
            FabulousVideoBean listBean= (FabulousVideoBean) data;
            if (listBean.getCode()==1){
                if (page==1){
                    recy.setVisibility(View.VISIBLE);
                    fabulousVideo = listBean.getData();
                    messageVideoadapter = new MessageVideoadapter(getActivity());
                    messageVideoadapter.setdeleteClick(new MessageVideoadapter.OnClick() {
                        @Override
                        public void item(int posttion) {
                            if (fabulousVideo.get(posttion).getFabulousType()==2){
                                Intent intent=new Intent(getActivity(), VideoActivity.class);
                                intent.putExtra("video_id",fabulousVideo.get(posttion).getVideoId()+"");
                                intent.putExtra("coverImg",fabulousVideo.get(posttion).getCoverImg()+"");
                                getActivity().startActivity(intent);
                            }else {
                                Intent intent=new Intent(getActivity(), ExtensionradioActivity.class);
                                intent.putExtra("extension_id",fabulousVideo.get(posttion).getVideoId()+"");
                                startActivity(intent);
                            }
                        }
                    });
                    messageVideoadapter.setaddClick(new MessageVideoadapter.OnIntentClick() {
                        @Override
                        public void item(int position) {
                            Map<String,String> map=new HashMap<>();
                            map.put("token",Constant.TOKEN);
                            map.put("uid",uid);
                            map.put("type","2");
                            map.put("cid",fabulousVideo.get(position).getFabulousId()+"");

                            pressenter.sendMessage(getActivity(),Constant.fabulouscancel,map,Bean.class);
                            fabulousVideo.remove(position);
                            messageVideoadapter.setList(fabulousVideo);
                        }
                    });

                    recy.setAdapter(messageVideoadapter);
                }else {
                    fabulousVideo.addAll(listBean.getData());
                }
                messageVideoadapter.setList(fabulousVideo);
                page++;
            }else {
                if (page==1){
                    recy.setVisibility(View.GONE);
                }
                Toast.makeText(getActivity(), listBean.getMessage(), Toast.LENGTH_SHORT).show();
            }

            recy.refreshComplete();
            recy.loadMoreComplete();

        }else if (data instanceof FavoriteArticleBean){
            FavoriteArticleBean listBean= (FavoriteArticleBean) data;
            if (listBean.getCode()==1){
                if (page==1){
                    recy.setVisibility(View.VISIBLE);
                    favoriteArticle = listBean.getData();
                    messageColletArticleadapter = new MessageColletArticleadapter(getActivity());
                    messageColletArticleadapter.setdeleteClick(new MessageColletArticleadapter.OnClick() {
                        @Override
                        public void item(int posttion) {
                            if (favoriteArticle.get(posttion).getFavoriteType()==1){
                                Intent intent=new Intent(getActivity(), ArticleActivity.class);
                                intent.putExtra("article_id",favoriteArticle.get(posttion).getArticleId()+"");
                                intent.putExtra("coverImg",favoriteArticle.get(posttion).getCoverImg()+"");
                                startActivity(intent);
                            }else {
                                Intent intent=new Intent(getActivity(), ExtensionarticleActivity.class);
                                intent.putExtra("extension_id",favoriteArticle.get(posttion).getArticleId()+"");
                                startActivity(intent);
                            }
                        }
                    });
                    messageColletArticleadapter.setaddClick(new MessageColletArticleadapter.OnIntentClick() {
                        @Override
                        public void item(int position) {
                            Map<String,String> map=new HashMap<>();
                            map.put("token",Constant.TOKEN);
                            map.put("uid",uid);
                            map.put("type","1");
                            map.put("cid",favoriteArticle.get(position).getFavoriteId()+"");

                            pressenter.sendMessage(getActivity(),Constant.cancel,map,Bean.class);
                            favoriteArticle.remove(position);
                            messageColletArticleadapter.setList(favoriteArticle);
                        }
                    });
                    recy.setAdapter(messageColletArticleadapter);
                }else {
                    favoriteArticle.addAll(listBean.getData());
                }
                messageColletArticleadapter.setList(favoriteArticle);
                page++;
            }else {
                if (page==1){
                    recy.setVisibility(View.GONE);
                }
                Toast.makeText(getActivity(), listBean.getMessage(), Toast.LENGTH_SHORT).show();
            }

            recy.refreshComplete();
            recy.loadMoreComplete();
        }else if (data instanceof FavoriteVideoBean){
            FavoriteVideoBean listBean= (FavoriteVideoBean) data;
            if (listBean.getCode()==1){
                if (page==1){
                    recy.setVisibility(View.VISIBLE);
                    favoriteVideo = listBean.getData();
                    messageCollectVideoadapter = new MessageCollectVideoadapter(getActivity());
                    messageCollectVideoadapter.setdeleteClick(new MessageCollectVideoadapter.OnClick() {
                        @Override
                        public void item(int posttion) {
                            if (favoriteVideo.get(posttion).getFavoriteType()==2){
                                Intent intent=new Intent(getActivity(), VideoActivity.class);
                                intent.putExtra("video_id",favoriteVideo.get(posttion).getVideoId()+"");
                                intent.putExtra("coverImg",favoriteVideo.get(posttion).getCoverImg()+"");
                                startActivity(intent);
                            }else {
                                Intent intent=new Intent(getActivity(), ExtensionradioActivity.class);
                                intent.putExtra("extension_id",favoriteVideo.get(posttion).getVideoId()+"");
                                startActivity(intent);
                            }
                        }
                    });
                    messageCollectVideoadapter.setaddClick(new MessageCollectVideoadapter.OnIntentClick() {
                        @Override
                        public void item(int position) {
                            Map<String,String> map=new HashMap<>();
                            map.put("token",Constant.TOKEN);
                            map.put("uid",uid);
                            map.put("type","2");
                            map.put("cid",favoriteVideo.get(position).getFavoriteId()+"");

                            pressenter.sendMessage(getActivity(),Constant.cancel,map,Bean.class);
                            favoriteVideo.remove(position);
                            messageCollectVideoadapter.setList(favoriteVideo);
                        }
                    });
                    recy.setAdapter(messageCollectVideoadapter);
                }else {
                    favoriteVideo.addAll(listBean.getData());
                }
                messageCollectVideoadapter.setList(favoriteVideo);
                page++;
            }else {
                if (page==1){
                    recy.setVisibility(View.GONE);
                }
                Toast.makeText(getActivity(), listBean.getMessage(), Toast.LENGTH_SHORT).show();
            }
            recy.refreshComplete();
            recy.loadMoreComplete();
        }else if (data instanceof Bean){
            Bean bean= (Bean) data;
            Toast.makeText(getActivity(), bean.getMessage(), Toast.LENGTH_SHORT).show();
            if (bean.getCode()==1){
                if (bean.getMessage().equals("清空成功")){
                    messageColletArticleadapter.setList(new ArrayList<FavoriteArticleBean.DataBean>());
                    messageCollectVideoadapter.setList(new ArrayList<FavoriteVideoBean.DataBean>());
                    messageArticleadapter.setList(new ArrayList<FabulousArticleBean.DataBean>());
                    messageVideoadapter.setList(new ArrayList<FabulousVideoBean.DataBean>());
                }
            }
        }else if (data instanceof GetExtensionListBean){
            GetExtensionListBean getExtensionListBean= (GetExtensionListBean) data;
            if (getExtensionListBean.getCode()==1){
                if (page==1){
                    recy.setVisibility(View.VISIBLE);
                    adapter = new ExtensionAdapter(getActivity());
                    adapter.setdeleteClick(new ExtensionAdapter.OnClick() {
                        @Override
                        public void item(int posttion) {
                            Intent intent;
                            switch (extensionType){
                                case "1":
                                    intent=new Intent(getActivity(), ExtensionarticleActivity.class);
                                    intent.putExtra("extension_id",beanList.get(posttion).getExtension_id()+"");
                                    startActivity(intent);
                                    break;
                                case "2":
                                    intent=new Intent(getActivity(), ExtensionradioActivity.class);
                                    intent.putExtra("extension_id",beanList.get(posttion).getExtension_id()+"");
                                    startActivity(intent);
                                    break;
                                default:
                            }
                        }
                    });

                    adapter.setaddClick(new ExtensionAdapter.OnIntentClick() {
                        @Override
                        public void item(int positions) {
                            Map<String,String> map=new HashMap<>();
                            map.put("token",Constant.TOKEN);
                            map.put("uid",uid);
                            map.put("extension_id",beanList.get(positions).getExtension_id()+"");
                            pressenter.sendMessage(getActivity(),Constant.del_extension,map, Bean.class);

                        }
                    });
                    beanList = getExtensionListBean.getData();
                    recy.setAdapter(adapter);
                }else {
                    beanList.addAll(getExtensionListBean.getData());
                }

                for (int i = 0; i < beanList.size(); i++) {
                    beanList.get(i).setType(1);
                }

                adapter.setList(beanList);
                page++;
            }else {
                if (page==1){
                    recy.setVisibility(View.GONE);
                }
            }
            recy.loadMoreComplete();
            recy.refreshComplete();
        }


    }
    private List<GetExtensionListBean.DataBean> beanList;
    private ExtensionAdapter adapter;
    @SuppressLint("NewApi")
    @OnClick({R.id.change, R.id.image_like, R.id.like, R.id.image_liked, R.id.liked, R.id.likedVideo})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.change:
                switch (change.getText().toString()){
                    case "清空收藏":
                        clearcollection();
                        break;
                    case "清空点赞":
                        clearlike();
                        break;
                        default:
                }
                break;
            case R.id.image_like:
                change.setVisibility(View.VISIBLE);
                textLike.setTextColor(getActivity().getResources().getColor(R.color.main));
                textLiked.setTextColor(Color.parseColor("#666666"));
                imageLike.setImageResource(R.mipmap.message_checks);
                imageLiked.setImageResource(R.mipmap.message_check);
                line_like.setVisibility(View.VISIBLE);
                line_liked.setVisibility(View.INVISIBLE);
                setBackgroundAlpha(0.5f);
                popWindow.showAsDropDown(view);
                break;
            case R.id.like:
                type="1";
                change.setText("清空收藏");
                textLike.setTextColor(getActivity().getResources().getColor(R.color.main));
                textLiked.setTextColor(Color.parseColor("#666666"));
                text_likedVideo.setTextColor(Color.parseColor("#666666"));
                imageLike.setImageResource(R.mipmap.message_checks);
                imageLiked.setImageResource(R.mipmap.message_check);
                line_like.setVisibility(View.VISIBLE);
                line_liked.setVisibility(View.INVISIBLE);
                line_likedVideo.setVisibility(View.INVISIBLE);
                page=1;
                getColletArticle();
                break;
            case R.id.likedVideo:
                type="1";
                change.setText("清空收藏");
                text_likedVideo.setTextColor(getActivity().getResources().getColor(R.color.main));
                textLiked.setTextColor(Color.parseColor("#666666"));
                textLike.setTextColor(Color.parseColor("#666666"));
                imageLike.setImageResource(R.mipmap.message_checks);
                imageLiked.setImageResource(R.mipmap.message_check);
                line_likedVideo.setVisibility(View.VISIBLE);
                line_liked.setVisibility(View.INVISIBLE);
                line_like.setVisibility(View.INVISIBLE);
                page=1;
                getColletVideo();
                break;
            case R.id.liked:
                type="2";
                change.setText("清空点赞");
                change.setVisibility(View.GONE);
                textLiked.setTextColor(getActivity().getResources().getColor(R.color.main));
                textLike.setTextColor(Color.parseColor("#666666"));
                text_likedVideo.setTextColor(Color.parseColor("#666666"));
                imageLiked.setImageResource(R.mipmap.message_checks);
                imageLike.setImageResource(R.mipmap.message_check);
                line_liked.setVisibility(View.VISIBLE);
                line_like.setVisibility(View.INVISIBLE);
                line_likedVideo.setVisibility(View.INVISIBLE);
                page=1;
                getLikeVideo();
                break;
            case R.id.image_liked:
                change.setVisibility(View.GONE);
                textLiked.setTextColor(getActivity().getResources().getColor(R.color.main));
                textLike.setTextColor(Color.parseColor("#666666"));
                imageLiked.setImageResource(R.mipmap.message_checks);
                imageLike.setImageResource(R.mipmap.message_check);
                line_liked.setVisibility(View.VISIBLE);
                line_like.setVisibility(View.INVISIBLE);
                setBackgroundAlpha(0.5f);
                popWindows.showAsDropDown(view);
                break;
            default:
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @Override
    public void fail(String error) {

    }



    private PopupWindow popWindow;
    private void showPopwindow() {
        View popView = View.inflate(getActivity(), R.layout.message_popup, null);
        TextView article_like = popView.findViewById(R.id.article_like);
        TextView article_collection = popView.findViewById(R.id.article_collection);
        TextView video_like = popView.findViewById(R.id.video_like);
        TextView video_collection = popView.findViewById(R.id.video_collection);
        article_like.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                page=1;
                getLikeArticle();
                textLike.setText("点赞文章");
                popWindow.dismiss();
            }
        });
        article_collection.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                page=1;
                textLike.setText("收藏文章");
                getColletArticle();
                popWindow.dismiss();
            }
        });
        video_like.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                page=1;
                textLike.setText("点赞视频");
                getLikeVideo();
                popWindow.dismiss();
            }
        });
        video_collection.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                page=1;
                type="2";
                textLike.setText("收藏视频");
                getColletVideo();
                popWindow.dismiss();
                change.setText("清空收藏");
            }
        });


        popWindow = new PopupWindow(popView, ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true);
        popWindow.setFocusable(true);
        popWindow.setTouchable(true);
        popWindow.setBackgroundDrawable(new BitmapDrawable());
        popWindow.setOutsideTouchable(true);// 设置允许在外点击消失

        popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                // popupWindow隐藏时恢复屏幕正常透明度
                setBackgroundAlpha(1.0f);
            }
        });

    }


    private PopupWindow popWindows;
    private void showPopwindows() {
        View popView = View.inflate(getActivity(), R.layout.message_popup, null);
        TextView article_like = popView.findViewById(R.id.article_like);
        TextView article_collection = popView.findViewById(R.id.article_collection);
        TextView video_like = popView.findViewById(R.id.video_like);
        TextView video_collection = popView.findViewById(R.id.video_collection);
        article_like.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                page=1;
//                getbeLikeArticle();
                textLiked.setText("点赞文章");
                popWindows.dismiss();
            }
        });
        article_collection.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                page=1;
                textLiked.setText("被收藏文章");
                extensionType="1";
                url=Constant.my_be_collect_article;
                getbeColletVideo();
                popWindows.dismiss();
            }
        });
        video_like.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                page=1;
                textLiked.setText("被点赞视频");
                extensionType="2";
                url=Constant.my_be_praised_article;
                getbeColletVideo();
                popWindows.dismiss();
            }
        });
        video_collection.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                page=1;
                textLiked.setText("被收藏视频");
                extensionType="2";
                url=Constant.my_be_collect_article;
                getbeColletVideo();
                popWindows.dismiss();
            }
        });

        popWindows = new PopupWindow(popView, ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true);
        popWindows.setFocusable(true);
        popWindows.setTouchable(true);
        popWindows.setBackgroundDrawable(new BitmapDrawable());
        popWindows.setOutsideTouchable(true);// 设置允许在外点击消失

        popWindows.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                // popupWindow隐藏时恢复屏幕正常透明度
                setBackgroundAlpha(1.0f);
            }
        });

    }

    private String extensionType;
    private String url;

    private void getbeColletVideo() {
        Map<String,String> map=new HashMap<>();
        map.put("token",Constant.TOKEN);
        map.put("uid",uid);
        map.put("type",extensionType);
        map.put("page",page+"");
        pressenter.sendMessage(getActivity(),url,map, GetExtensionListBean.class);
    }

    /**
     * 设置添加屏幕的背景透明度
     *
     * @param bgAlpha 屏幕透明度0.0-1.0 1表示完全不透明
     */
    public void setBackgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = getActivity().getWindow()
                .getAttributes();
        lp.alpha = bgAlpha;
        getActivity().getWindow().setAttributes(lp);
    }


}
